package com.zmzncs.lmtc.module.order.controller;


import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.pojo.bolian.BolianOrderHistoryRes;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.order.pojo.order_Info.BolianOrderHistoryForm;
import com.zmzncs.lmtc.module.order.pojo.order_trade_record.OrderTradeRecordDTO;
import com.zmzncs.lmtc.module.order.pojo.order_trade_record.OrderTradeRecordTableVO;
import com.zmzncs.lmtc.module.order.service.OrderTradeRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 订单-订单交易记录 前端控制器
 * </p>
 *
 * @author 任建波
 * @since 2020-09-24
 */
@Api(tags = "订单交易记录")
@RestController
@RequestMapping("/order/trade-record")
@Validated
@Slf4j
public class OrderTradeRecordController {

    @Autowired
    OrderTradeRecordService orderTradeRecordService;

    @ApiOperation(value = "根据订单号查询订单交易记录")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType = "query", name = "orderCode", value = "orderCode" , required = true ),
    })
    @GetMapping(value = "getOrderTradeRecordByOrderCode")
    public Rest<List<OrderTradeRecordTableVO>> getOrderTradeRecordByOrderCode(@NotNull String orderCode) {
        List<OrderTradeRecordDTO> list = orderTradeRecordService.getOrderTradeRecordByOrderCode(orderCode);
        List<OrderTradeRecordTableVO> orderTradeRecordTableVOList = JsonUtil.listTransform(list, OrderTradeRecordTableVO.class);

        return RestUtil.success(orderTradeRecordTableVOList);
    }

    @ApiOperation(value = "根据订单编号查询泊链历史订单")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping(value = "/getBolianOrderByOrderCode")
    public Rest<BolianOrderHistoryRes> getBolianOrderByOrderCode(@NotNull String orderCode){
        BolianOrderHistoryRes bolianOrderHistoryRes = orderTradeRecordService.getBolianOrderByOrderCode(orderCode);
        return RestUtil.success(bolianOrderHistoryRes);
    }


    @ApiOperation(value = "查询泊链历史订单")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping(value = "/getBolianOrderHistory")
    public Rest<BolianOrderHistoryRes> getBolianOrderHistory(@RequestBody @Valid BolianOrderHistoryForm form){
        BolianOrderHistoryRes bolianOrderHistoryRes = orderTradeRecordService.getBolianOrderHistory(form);
        return RestUtil.success(bolianOrderHistoryRes);
    }


}

